<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>编辑后台管理员</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <script th:src="@{/layui/jquery.min.js}"></script>
    <style type="text/css">
        .layui-input {
            width: 300px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <p style="color: red" id="add-msg"></p>

    <div class="layui-form-item">
        <label class="layui-form-label">管理员ID</label>
        <div class="layui-input-block">
            <input type="text" id="adminId" name="adminId" required lay-verify="required"
                   th:each="userRolePrivileges,userRolePrivilegesStat:${map.userRolePrivilegesList}"
                   th:if="${userRolePrivilegesStat.index==0}" th:value="${userRolePrivileges.adminId}"
                   readonly="readonly" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">管理员名称</label>
        <div class="layui-input-inline">
            <input type="text" id="adminName" name="adminName" required lay-verify="required"
                   th:each="userRolePrivileges,userRolePrivilegesStat:${map.userRolePrivilegesList}"
                   th:if="${userRolePrivilegesStat.index==0}" th:value="${userRolePrivileges.adminName}"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-inline">
            <input type="text" id="realName" name="realName" required lay-verify="required"
                   th:each="userRolePrivileges,userRolePrivilegesStat:${map.userRolePrivilegesList}"
                   th:if="${userRolePrivilegesStat.index==0}" th:value="${userRolePrivileges.realName}"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block" th:each="userRolePrivileges,userRolePrivilegesStat:${map.userRolePrivilegesList}">
            <div class="layui-input-block">
                <input class="role-id" type="hidden" name="rName" lay-skin="primary" th:value="${userRolePrivileges.roleId}">
                <input class="role-name"   type="checkbox" name="rName" lay-skin="primary" th:title="${userRolePrivileges.rName}" checked="">
            </div>
        </div>
    </div>


    <form>
        <div class="layui-form-item">
            <label class="layui-form-label">增加角色</label>
            <div class="layui-input-block" th:each=" role:${map.roleList}">
                <div class="layui-input-block">
                    <input class="role-id" type="hidden" name="rName" lay-skin="primary" th:title="${role.roleId}">
                    <input class="role-name" th:id="${'roleId'+role.roleId}"  type="checkbox" name="rName" lay-skin="primary" th:title="${role.rName}">
                </div>
            </div>
        </div>
    </form>


</form>
<script th:src="@{/layui/layui.js}"></script>
<script>
    layui.use('form', function () {
        var form = layui.form;
    });

    //设置获取的值相应的显示
    setShow();

    function setShow() {
        var roleId = $('#roleId').val();
        var roleIds = parseInt(roleId);
        switch (roleIds) {
            case 5:
                $('#admin').attr('checked', 'checked');
                break;
            case 6:
                $('#supper-admin').attr('checked', 'checked');
                break;
        }
    }

    //显示角色
$(function () {
      showRole();
  })

function  showRole() {
      var adminId= $('#adminId').val();

       $.ajax({
           url:'/queryAdminRolePrivilege?adminId='+adminId,
           success:function (res) {
            var userRoleId=res.userRolePrivileges.roleId;
            if(true){
                $('#roleId'+userRoleId).prop('checked',true);
            }
           }
       })
   }



</script>
</body>
</html>